#!/usr/bin/env python
# Create: 2020/1/17
__author__ = '749B'

from conf import settings


def parse(msg):
    syslog_fields = msg.split("%s:" % settings.SYSLOG_MSG_TAG, 1)
    if len(syslog_fields) != 2:
        return
    syslog_msg_content = syslog_fields[1].strip()
    syslog_msg_content_fields = syslog_msg_content.split(":", 1)
    if len(syslog_msg_content_fields) != 2:
        return
    return syslog_msg_content_fields


def run(msgs):
    while True:
        msg = msgs.get()
        res_fields = parse(msg)
        if not res_fields:
            continue
        action = settings.SYSLOG_MSG_ACTIONS.get(res_fields[0])
        detail = res_fields[1]
        print("%s: %s" % (action, detail))


